// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Attach a marker to an object
// -----------------------------------------------

private [
	"_indexparameters",
	"_refreshtime",
	"_markername",
	"_markersize",
	"_markercolor",
	"_markershape",
	"_markerbrush",
	"_protect",
	"_parameters",
	"_nbparameters",
	"_markerposition",
	"_object",
	"_marker",
	"_markertype",
	"_markerdir",
	"_markertext"
];

_parameters = [
	"_object",
	"_markername",
	"_markersize",
	"_markercolor",
	"_markershape",
	"_markerbrush",
	"_refreshtime",
	"_markertype",
	"_markerdir",
	"_markertext",
	"_protect"
];

_indexparameters = 0;
_nbparameters = count _this;
{
	if (_indexparameters <= _nbparameters) then {
		call compile format ["%1 = _this select %2;", _x, _indexparameters];
	};
	_indexparameters = _indexparameters + 1;
} foreach _parameters;

if (isNil "_refreshtime") then { _refreshtime = 4 };
if (isNil "_markername") then {  _markername = "dummy" };
if (isNil "_markersize") then {  _markersize = 50 };
if (_markercolor == "") then {   _markercolor = "ColorRed" };
if (isNil "_markershape") then { _markershape = "ELLIPSE" };
if (_markerbrush == "") then {   _markerbrush = "FDIAGONAL" };
if (isNil "_protect") then {     _protect = false };

_markerposition = getPos _object;
_marker = [_markername, _markersize, _markerposition, _markercolor, _markershape, _markerbrush, _markertype, _markerdir, _markertext, _protect] call WC_fnc_createmarker;

while {alive _object} do {
	_marker setMarkerPos (getPos _object);
	sleep _refreshtime;
};

deleteMarker _marker;